package com.ny.view;



import com.ny.dao.ManagerDao;
import com.ny.dao.impl.ManagerDaoImpl;
import com.ny.entity.Order;
import com.ny.entity.Stud;
import com.ny.service.ManagerService;
import com.ny.service.OrderService;
import com.ny.service.ProductService;
import com.ny.service.StudentService;
import com.ny.service.impl.ManagerServiceImpl;
import com.ny.service.impl.OrderServiceImpl;
import com.ny.service.impl.ProductServiceImpl;
import com.ny.service.impl.StudentServiceImpl;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class ManagerView {
    //六、管理员登录的界面
    //1.个人管理：个人信息的修改
    //2.用户管理：对其他用户进行操作（删除、修改、添加、查询）
    //3.商品管理：添加、删除、修改、查询商品
    //4.订单管理：添加、删除、修改、查询订单
    private Scanner scanner = new Scanner(System.in);
    Stud stud = new Stud();
    StudentService studentService = new StudentServiceImpl();
    ProductService productService = new ProductServiceImpl();
    OrderService orderService = new OrderServiceImpl();
    public void showManagerView() throws SQLException, ClassNotFoundException {
        boolean f = true;
        Stud stud = new Stud();
        StudentService studentService = new StudentServiceImpl();
        ProductService productService = new ProductServiceImpl();
        OrderService orderService = new OrderServiceImpl();
         while (f) {
             System.out.println("请选择你的操作");
             System.out.println("1.用户管理");
             System.out.println("2.商品管理");
             System.out.println("3.订单管理");
             System.out.println("0.退出系统");
             int choice = scanner.nextInt();
        switch (choice){
                 case 1:
                     System.out.println("用户管理界面");
                     System.out.println("1.添加用户");
                     System.out.println("2.删除用户");
                     System.out.println("3.修改用户");
                     System.out.println("4.查询用户");
                     int choice1 = scanner.nextInt();
                     switch (choice1){
                         case  1:
                             System.out.println("1.添加用户");
                             ReguserView  reguserView = new ReguserView();
                             reguserView.showRegisterForm();
                             break;
                         case 2:
                             System.out.println("2.删除用户");
                             DeleteView deleteView = new DeleteView();
                             deleteView.showDeleteForm();
                             break;
                         case 3:
                             System.out.println("3.修改用户");
                             System.out.println("4.修改用户密码");
                             System.out.println("5.修改用户手机号");
                             int choice3 = scanner.nextInt();
                             switch (choice3){
                                 case 4:
                                     System.out.println("4.修改用户密码");
                                     String name = stud.getStuName();
                                     System.out.println("请输入旧密码");
                                     String pwd = scanner.next();
                                     if (pwd.equals(stud.getStuPwd())) {
                                         System.out.println("请输入新密码");
                                         String newpwd = scanner.next();


                                         Stud stud1  = studentService.changePwd(name, pwd);
                                         if (stud1 != null) {
                                             stud1.setStuPwd(newpwd);
                                             studentService.changePwd(name, newpwd);
                                             System.out.println("修改成功");
                                         } else {
                                             System.out.println("修改失败");

                                         }
                                     }else {
                                         System.out.println("旧密码错误,无法修改");
                                     }
                                     break;
                                 case 5:
                                     System.out.println("5.修改用户手机号");
                                     System.out.println("请输入用户名");
                                     String name1 = scanner.next();
                                     if (name1.equals(stud.getStuName())){
                                         System.out.println("请输入旧的手机号");
                                         String phone = scanner.next();
                                         if (phone.equals(stud.getStuPhone())) {
                                             System.out.println("请输入新的手机号");
                                             String newphone = scanner.next();
                                             Stud stud2 = studentService.changePho(name1, phone);
                                             if (stud2 != null) {
                                                 stud2.setStuPhone(newphone);
                                                 studentService.changePho(name1, newphone);
                                                 System.out.println("修改成功");
                                             } else {
                                                 System.out.println("修改失败");
                                             }
                                         } else {
                                             System.out.println("手机号错误,无法修改");
                                         }
                                     }

                                     break;
                                 default:
                                     System.out.println("输入错误");
                                     break;
                             }

                             break;
                         case 4:
                             System.out.println("4.查询用户");
                             SelectView selectView = new SelectView();
                             selectView.showSelectStudForm();
                             break;
                         default:
                             System.out.println("输入错误");
                             break;
                     }
                     break;
                     case 2:
                       System.out.println("2.商品管理");
                         System.out.println("1.添加商品");
                         System.out.println("2.删除商品");
                         System.out.println("3.修改商品");
                         System.out.println("4.查询商品");
                         int choice2 = scanner.nextInt();
                         switch (choice2){
                             case 1:
                                 System.out.println("1.添加商品");
                                 ProductView productView = new ProductView();
                                 productView.showAddProductForm();
                                 showManagerView();
                                 break;
                             case 2:
                                 System.out.println("2.删除商品");
                                 DeleteView  deleteProductView = new DeleteView();
                                 deleteProductView.showDeleteProForm();
                                 break;
                             case 3:
                                 System.out.println("3.修改商品");
                                 break;
                             case 4:
                                 System.out.println("4.查询商品");
                                 SelectView selectProductView = new SelectView();
                                 selectProductView.showSelectProForm();
                                 break;
                             default:
                                 System.out.println("输入错误");
                         }
                         break;
                     case 3:
                       System.out.println("3.订单管理");
                         System.out.println("1.查看所有订单");
                         System.out.println("2.查询订单");
                         int choice3 = sc.nextInt();
                         switch (choice3){
                             case 1:
                                 System.out.println("1.查看所有订单");
                                 List<Order> list1 = orderService.findAllOrder();
                                 System.out.println("订单id"  + "\t" + "商品id" + "\t" + "商品数量" + "\t" + "总价");
                                 for (Order order : list1) {
                                     System.out.print(order.getOrder_id());
                                     System.out.print("\t" + "\t");
                                     System.out.print(order.getProduct_id());
                                     System.out.print("\t" + "\t");
                                     System.out.print(order.getNumber());
                                     System.out.print("\t" + "\t");
                                     System.out.println(order.getTotal_price());

                                 }
                                 System.out.println("1.返回");
                                 int choice4 = scanner.nextInt();
                                 switch (choice4) {
                                     case 1:
                                         showManagerView();
                                         break;
                                 }
                                 break;
                             case 2:
                                 System.out.println("2.查询某一订单");
                                 break;
                             default:
                                 System.out.println("输入错误");
                         }
                         break;
                     case 0:
                       System.out.println("0.退出系统");
                         return;
             }

        }
    }


